/********************************************************************************
*																				*
*  Las Venturas Playground - Commands/adminCommands.nut							*
*																				*
*  This file will hold all admin commands.										*
*																				*
********************************************************************************/

function onPlayerAdminCommand(playerid, command)
{
	local cmd = split(command.tolower(), " ");

	// Command: /p
	// Params: (int) 
	// Params: (int) (string)
	// Author: Sander
	if(cmd[0] == "/p")
	{
		// Syntax: /p (playerID) (parameter) (int)
		if(cmd.len() == 4)
		{	
			// Command: /p [playerID] health (int)
			// Params: (int) player
			// Author: Sander
			if(cmd[2] == "health")
			{
				// Function: Is the player connected?
				if(!isPlayerConnected ( cmd[1].tointeger() ))
				{
					sendPlayerMessage(playerid, "[FF0000FF]/[FFFF0000]![FF0000FF]\\ The requested player with [FFFF0000]ID "+ cmd[1].tointeger() +"[FF0000FF] is not connected.", 0xFFFFFFFF, true);
					return 1;
				}
				
				// Is the value between 0 and 100?
				local iPlayerHealth = cmd[3].tointeger();
				if(iPlayerHealth >=0 && iPlayerHealth <=100)
				{
					setPlayerHealth ( cmd[1].tointeger(), iPlayerHealth )
					// Inform the crewmember
					sendPlayerMessage(playerid, "*** "+ getPlayerName( cmd[1].tointeger() ) +"s health is now: " + iPlayerHealth + "!", 0xFFFFFFFF, true);
					return 1;
				}
				else
				{
					sendPlayerMessage(playerid, "[FF0000FF]* Usage: [FFFF0000]/p [PlayerID] health [0-100].", 0xFFFFFFFF, true);
					return 1;
				}
			}
			
			// Command: /p [playerID] vehiclehealth (int)
			// Params: (int) player
			// Author: Sander
			if(cmd[2] == "vehiclehealth")
			{
				// Function: Is the player connected?
				if(!isPlayerConnected ( cmd[1].tointeger() ))
				{
					sendPlayerMessage(playerid, "[FF0000FF]/[FFFF0000]![FF0000FF]\\ The requested player with [FFFF0000]ID "+ cmd[1].tointeger() +"[FF0000FF] is not connected.", 0xFFFFFFFF, true);
					return 1;
				}
				//Function: Is the player in any vehicle?
				if(!isPlayerInAnyVehicle( playerid ))
				{
					sendPlayerMessage(playerid, "[FF0000FF]/[FFFF0000]![FF0000FF]\\ "+getPlayerName( cmd[1].tointeger())+" is not in any vehicle!", 0xFFFFFFFF, true);
					return 1;
				}
				
				// Is the value between 0 and 1000?
				local iVehicleHealth = cmd[3].tointeger();
				if(iVehicleHealth >=0 && iVehicleHealth <=1000)
				{
					// Set the players vehiclehealth
					setVehicleEngineHealth(getPlayerVehicleId(cmd[1].tointeger()), iVehicleHealth);
				
					// Inform the crewmember
					sendPlayerMessage(playerid, "*** "+ getPlayerName( cmd[1].tointeger() ) +"s vehiclehealth is now: " + iVehicleHealth + "!", 0xFFFFFFFF, true);
					return 1;
				}
				// Invalid value, show usage.
				else
				{
					sendPlayerMessage(playerid, "[FF0000FF]* Usage: [FFFF0000]/p [PlayerID] vehiclehealth [0-1000].", 0xFFFFFFFF, true);
					return 1;
				}
			}			
		}
		
		// Syntax: /p (playerID) (parameter)
		if(cmd.len() == 3)
		{	
			// Command: /p [playerID] health
			// Params: (int) player
			// Author: Sander
			if(cmd[2] == "health")
			{
				// Function: Is the player connected?
				if(!isPlayerConnected ( cmd[1].tointeger() ))
				{
					sendPlayerMessage(playerid, "[FF0000FF]/[FFFF0000]![FF0000FF]\\ The requested player with [FFFF0000]ID "+ cmd[1].tointeger() +"[FF0000FF] is not connected.", 0xFFFFFFFF, true);
					return 1;
				}
				
				// Get the players health
				local iPlayerHealth = getPlayerHealth ( cmd[1].tointeger() );
				// Inform the crewmember
				sendPlayerMessage(playerid, "*** "+ getPlayerName( cmd[1].tointeger() ) +"s health is: " + iPlayerHealth + "!", 0xFFFFFFFF, true);
				return 1;				
			}		
			
			// Command: /p [playerID] vehiclehealth
			// Params: (int) player
			// Author: Sander
			if(cmd[2] == "vehiclehealth")
			{
		
				// Function: Is the player connected?
				if(!isPlayerConnected ( cmd[1].tointeger() ))
				{
					sendPlayerMessage(playerid, "[FF0000FF]/[FFFF0000]![FF0000FF]\\ The requested player with [FFFF0000]ID "+ cmd[1].tointeger() +"[FF0000FF] is not connected.", 0xFFFFFFFF, true);
					return 1;
				}
				
				// Function: Is the player in any vehicle?
				if(!isPlayerInAnyVehicle( playerid ))
				{
					sendPlayerMessage(playerid, "[FF0000FF]/[FFFF0000]![FF0000FF]\\ "+getPlayerName( cmd[1].tointeger())+" is not in any vehicle!", 0xFFFFFFFF, true);
					return 1;
				}

				// Get the vehicleID
				local iVehID = getPlayerVehicleId( cmd[1].tointeger() );
				// And the vehicle health.
				local fVehHealth = getVehicleEngineHealth ( iVehID );
				
				// Inform the crewmember
				sendPlayerMessage(playerid, "*** "+getPlayerName( cmd[1].tointeger())+"s vehicle health is " + fVehHealth + "!", 0xFFFFFFFF, true);
				return 1;		
			}
			
			// Command: /p [playerID] weapon
			// Params: (int) player
			// Author: Sander
			if(cmd[2] == "weapon")
			{
				// Function: Is the player connected?
				if(!isPlayerConnected ( cmd[1].tointeger() ))
				{
					sendPlayerMessage(playerid, "[FF0000FF]/[FFFF0000]![FF0000FF]\\ The requested player with [FFFF0000]ID "+ cmd[1].tointeger() +"[FF0000FF] is not connected.", 0xFFFFFFFF, true);
					return 1;
				}
				
				// Retrieve weapon information of the current weapon.
				local iPlayerWeapon= getPlayerWeapon ( cmd[1].tointeger() );
				// Inform the crewmember
				sendPlayerMessage(playerid, "*** "+ getPlayerName( cmd[1].tointeger() ) +" has the following weapon: " + iPlayerWeapon + "!", 0xFFFFFFFF, true);
				return 1;
			}			
			
			// If noone of the above parameters was given, show an error message.
			else
			{
				sendPlayerMessage(playerid, "[FF0000FF]* Wrong parameter. [FF0000FF] See [FFFF0000]/p info [FF0000FF] for available command options.", 0xFFFFFFFF, true);
				return 1;
			}
		}
		
		// Syntax: /p (parameter)
		if(cmd.len() == 2)
		{
			// Show the available options to the crewmember.
			if(cmd[1] == "info")
			{
				sendPlayerMessage(playerid, "[FF0000FF]* Usage: [FFFF0000]/p [PlayerID] [FFFFFFFF]health [int], vehiclehealth [int], weapon", 0xFFFFFFFF, true);
				return 1;
			}
			
			// Forgot one parameter? We like to help you in the right direction!
			else
			{
				sendPlayerMessage(playerid, "[FF0000FF]* Wrong Usage: [FFFF0000]/p [PlayerID] [Command][FF0000FF] See [FFFF0000]/p info [FF0000FF]for available options.", 0xFFFFFFFF, true);
				return 1;
			}			
		}
		
		// No extra parameters given? Show the usage.
		else
		{
			sendPlayerMessage(playerid, "[FF0000FF]* Usage: [FFFF0000]/p [PlayerID] [parameter][FF0000FF] See [FFFF0000]/p info [FF0000FF]for available options.", 0xFFFFFFFF, true);
			return 1;
		}
		return 1;
	}

	// Command: /respawn
	// Params: void
	// Author: Sander
	
	if(cmd[0] == "/respawn")
	{
		// Loop through all the vehicles and delete them.
		for(local i = 0; i < MAX_VEHICLES; i++) deleteVehicle(i);
		
		// And call the spawn function
		spawnVehicle();
		return 1;
	}
	
	// Command: /v
	// Params: (playerID) (parameter)
	// Author: Sander
	if(cmd[0] == "/v")
	{
		// Syntax: /p (playerID) (parameter) (value1) (value2)
		if(cmd.len() == 5)
		{
			if(cmd[2] =="color")
			{
				// Function: Is the player connected?
				if(!isPlayerConnected ( cmd[1].tointeger() ))
				{
					sendPlayerMessage(playerid, "[FF0000FF]/[FFFF0000]![FF0000FF]\\ The requested player with [FFFF0000]ID "+ cmd[1].tointeger() +"[FF0000FF] is not connected.", 0xFFFFFFFF, true);
					return 1;
				}

				// Function: Is the player in any vehicle?
				if(!isPlayerInAnyVehicle( playerid ))
				{
					sendPlayerMessage(playerid, "[FF0000FF]/[FFFF0000]![FF0000FF]\\ "+getPlayerName( cmd[1].tointeger())+" is not in any vehicle!", 0xFFFFFFFF, true);
					return 1;
				}				

				// Get the vehicleID
				local iVehID = getPlayerVehicleId( cmd[1].tointeger() );
				setVehicleColor ( iVehID, cmd[3].tointeger(), cmd[4].tointeger(), 0, 0);
				return 1;				
			}
		}
		
		if(cmd.len() == 4)
		{
			// Command: /v [playerID] health (int)
			// Params: (int) player
			// Author: Sander
			if(cmd[2] == "health")
			{
				// Function: Is the player connected?
				if(!isPlayerConnected ( cmd[1].tointeger() ))
				{
					sendPlayerMessage(playerid, "[FF0000FF]/[FFFF0000]![FF0000FF]\\ The requested player with [FFFF0000]ID "+ cmd[1].tointeger() +"[FF0000FF] is not connected.", 0xFFFFFFFF, true);
					return 1;
				}
				//Function: Is the player in any vehicle?
				if(!isPlayerInAnyVehicle( playerid ))
				{
					sendPlayerMessage(playerid, "[FF0000FF]/[FFFF0000]![FF0000FF]\\ "+getPlayerName( cmd[1].tointeger())+" is not in any vehicle!", 0xFFFFFFFF, true);
					return 1;
				}
				
				// Is the value between 0 and 1000?
				local iVehicleHealth = cmd[3].tointeger();
				if(iVehicleHealth >=0 && iVehicleHealth <=1000)
				{
					// Set the players vehiclehealth
					setVehicleEngineHealth(getPlayerVehicleId(cmd[1].tointeger()), iVehicleHealth);
				
					// Inform the crewmember
					sendPlayerMessage(playerid, "*** "+ getPlayerName( cmd[1].tointeger() ) +"s vehicle health is now: " + iVehicleHealth + "!", 0xFFFFFFFF, true);
					return 1;
				}
				// Invalid value, show usage.
				else
				{
					sendPlayerMessage(playerid, "[FF0000FF]* Usage: [FFFF0000]/v [PlayerID] health [0-1000].", 0xFFFFFFFF, true);
					return 1;
				}
			}		
		}
		
		if(cmd.len() == 3)
		{
			// Command: /p [playerID] vehiclehealth
			// Params: (int) player
			// Author: Sander
			if(cmd[2] == "health")
			{
		
				// Function: Is the player connected?
				if(!isPlayerConnected ( cmd[1].tointeger() ))
				{
					sendPlayerMessage(playerid, "[FF0000FF]/[FFFF0000]![FF0000FF]\\ The requested player with [FFFF0000]ID "+ cmd[1].tointeger() +"[FF0000FF] is not connected.", 0xFFFFFFFF, true);
					return 1;
				}
				
				// Function: Is the player in any vehicle?
				if(!isPlayerInAnyVehicle( playerid ))
				{
					sendPlayerMessage(playerid, "[FF0000FF]/[FFFF0000]![FF0000FF]\\ "+getPlayerName( cmd[1].tointeger())+" is not in any vehicle!", 0xFFFFFFFF, true);
					return 1;
				}

				// Get the vehicleID
				local iVehID = getPlayerVehicleId( cmd[1].tointeger() );
				// And the vehicle health.
				local fVehHealth = getVehicleEngineHealth ( iVehID );
				
				// Inform the crewmember
				sendPlayerMessage(playerid, "*** "+getPlayerName( cmd[1].tointeger())+"s vehicle health is " + fVehHealth + "!", 0xFFFFFFFF, true);
				return 1;
			}

			// Command: /p [playerID] respawn
			// Params: (int) player
			// Author: Sander
			if(cmd[2] == "respawn")
			{
				// Function: Is the player connected?
				if(!isPlayerConnected ( cmd[1].tointeger() ))
				{
					sendPlayerMessage(playerid, "[FF0000FF]/[FFFF0000]![FF0000FF]\\ The requested player with [FFFF0000]ID "+ cmd[1].tointeger() +"[FF0000FF] is not connected.", 0xFFFFFFFF, true);
					return 1;
				}
				// Function: Is the player in any vehicle?
				
				if(!isPlayerInAnyVehicle( playerid ))
				{
					sendPlayerMessage(playerid, "[FF0000FF]/[FFFF0000]![FF0000FF]\\ "+getPlayerName( cmd[1].tointeger())"+ is not in any vehicle!", 0xFFFFFFFF, true);
					return 1;
				}

				// Get the vehicleID
				local iVehID = getPlayerVehicleId( cmd[1].tointeger() );
				// Respawn the vehicle
				deleteVehicle ( iVehID );
			}
			
		}
		
		// Check for one parameter after the command.
		if(cmd.len() == 2)
		{
			// Show the available options to the crewmember.
			if(cmd[1] == "info")
			{
				sendPlayerMessage(playerid, "[FF0000FF]* Usage: [FFFF0000]/v [PlayerID] [FFFFFFFF]color, fix, health [int], respawn", 0xFFFFFFFF, true);
				return 1;
			}
			
			// Forgot one parameter? We like to help you in the right direction!
			else
			{
				sendPlayerMessage(playerid, "[FF0000FF]* Wrong Usage: [FFFF0000]/v [PlayerID] [parameter][FF0000FF] See [FFFF0000]/v info [FF0000FF]for available options.", 0xFFFFFFFF, true);
				return 1;
			}			
		}		
		
		// No extra parameters given? Show the usage.
		else
		{
			sendPlayerMessage(playerid, "[FF0000FF]* Usage: [FFFF0000]/v [PlayerID] [Command][FF0000FF] See [FFFF0000]/v info [FF0000FF]for available options.", 0xFFFFFFFF, true);
			return 1;
		}	
	}
	
	return 0;
}